<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>basen.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">basen.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    Numeric base conversion library.  Works for arbitrary bases and
 arbitrary length numbers.

 For base-64 conversion use base64.js because it is optimized for the specific
 conversion to base-64 while this module is generic.  Base-64 is defined here
 mostly for demonstration purpose.

 TODO: Make base64 and baseN classes that have common interface.  (Perhaps...)
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_crypt_basen.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/closure/goog/crypt/basen.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">crypt/basen.js</div>
    </div>
  </div>
<hr/>


   
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.crypt.baseN.arrayToString_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">arrayToString_<span class="args">(<span class="arg">number</span>,&nbsp;<span class="arg">base</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
      </div>


     <div class="entryOverview">
       Converts an array representation of a number to a string.

More precisely, the elements of the input array are indices into the base,
which is represented as a string, which can either be user defined or one of
the BASE_xxx constants.

Throws an Error if the number contains a digit which is outside the range
0 ... base.length - 1.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">number</span>
        : <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>&gt;<span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
        <div class="entryOverview">Array of digit values, least significant first.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">base</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">Digits in the base.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>&nbsp;
            Number as a string, most significant digit first.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line230">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.crypt.baseN.recodeString"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">recodeString<span class="args">(<span class="arg">number</span>,&nbsp;<span class="arg">inputBase</span>,&nbsp;<span class="arg">outputBase</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
      </div>


     <div class="entryOverview">
       Converts a number from one numeric base to another.

The bases are represented as strings, which list allowed digits.  Each digit
should be unique.  The bases can either be user defined, or any of
goog.crypt.baseN.BASE_xxx.

The number is in human-readable format, most significant digit first, and is
a non-negative integer.  Base designators such as $, 0x, d, b or h (at end)
will be interpreted as digits, so avoid them.  Leading zeros will be trimmed.

Note: for huge bases the result may be inaccurate because of overflowing
64-bit doubles used by JavaScript for integer calculus.  This may happen
if the product of the number of digits in the input and output bases comes
close to 10^16, which is VERY unlikely (100M digits in each base), but
may be possible in the future unicode world.  (Unicode 3.2 has less than 100K
characters.  However, it reserves some more, close to 1M.)
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">number</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The number to convert.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">inputBase</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The numeric base the number is in (all digits).</div>
     </td>
   </tr>
     
   <tr class="even">
     <td>
        <span class="entryName">outputBase</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">Requested numeric base.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>&nbsp;
            The converted number.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line104">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.crypt.baseN.stringToArray_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">stringToArray_<span class="args">(<span class="arg">number</span>,&nbsp;<span class="arg">base</span>)</span>
        </span>
        &#8658; <div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>&gt;<span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>
      </div>


     <div class="entryOverview">
       Converts a string representation of a number to an array of digit values.

More precisely, the digit values are indices into the number base, which
is represented as a string, which can either be user defined or one of the
BASE_xxx constants.

Throws an Error if the number contains a digit not found in the base.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">number</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">The string to convert, most significant digit first.</div>
     </td>
   </tr>
     
   <tr class="odd">
     <td>
        <span class="entryName">base</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
        <div class="entryOverview">Digits in the base.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType">(<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number">number</a></span>&gt;<span>&nbsp;|&nbsp;</span><span class="type">null</span>)</div>&nbsp;
            Array of digit values, least significant digit first.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line194">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_64"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_64</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       The more-known version of the BASE-64 encoding.  Uses + and / characters.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line69">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_64_URL_SAFE"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_64_URL_SAFE</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       URL-safe version of the BASE-64 encoding.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line77">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_BINARY"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_BINARY</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       Base-2, i.e. '01'.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line34">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_DECIMAL"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_DECIMAL</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       Base-10, i.e. '0123456789'.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line48">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_LOWERCASE_HEXADECIMAL"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_LOWERCASE_HEXADECIMAL</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       Base-16 using lower case, i.e. '0123456789abcdef'.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line55">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_OCTAL"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_OCTAL</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       Base-8, i.e. '01234567'.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line41">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>





  <a name="goog.crypt.baseN.BASE_UPPERCASE_HEXADECIMAL"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.crypt.baseN.</span><span class="entryName">BASE_UPPERCASE_HEXADECIMAL</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span></div>
     </div>


     <div class="entryOverview">
       Base-16 using upper case, i.e. '0123456789ABCDEF'.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_crypt_basen.js.source.html#line62">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory crypt</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="crypt/basen.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
